package com.ukao.cashregister.ui.stokin;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gprinterio.GpDevice;
import com.mcxtzhang.commonadapter.rv.OnItemClickListener;
import com.ukao.cashregister.R;
import com.ukao.cashregister.adapter.StockinAdapter;
import com.ukao.cashregister.base.MvpFragment;
import com.ukao.cashregister.bean.AllMarkprintBean;
import com.ukao.cashregister.bean.MarkprintBean;
import com.ukao.cashregister.bean.MercCityBean;
import com.ukao.cashregister.bean.PayInfoBean;
import com.ukao.cashregister.bean.ProductRelImgBean;
import com.ukao.cashregister.bean.ReceiptBean;
import com.ukao.cashregister.bean.StockinBean;
import com.ukao.cashregister.consts.AppConstant;
import com.ukao.cashregister.dialog.BindSignDialogFragment;
import com.ukao.cashregister.dialog.DialogTool;
import com.ukao.cashregister.dialog.InquiryDialogFragment;
import com.ukao.cashregister.dialog.IntoBagDialogFragment;
import com.ukao.cashregister.dialog.SelectNumDialogFragment;
import com.ukao.cashregister.dialog.TansNoDialogFragment;
import com.ukao.cashregister.listener.MyOnItemClickListener;
import com.ukao.cashregister.listener.OnDialogSureClickListener;
import com.ukao.cashregister.listener.OnItemChildClickListener;
import com.ukao.cashregister.pesenter.StockinPesenter;
import com.ukao.cashregister.printer.PrintMiuiHelper;
import com.ukao.cashregister.printer.PrinterHelper;
import com.ukao.cashregister.printer.PrinterReceipt;
import com.ukao.cashregister.ui.CameraActivity;
import com.ukao.cashregister.ui.CameraSunMiActivity;
import com.ukao.cashregister.ui.MainActivity;
import com.ukao.cashregister.utils.CheckUsbDeviceUtils;
import com.ukao.cashregister.utils.CheckUtils;
import com.ukao.cashregister.utils.DecimalUtil;
import com.ukao.cashregister.utils.DensityUtils;
import com.ukao.cashregister.utils.MyDateUtils;
import com.ukao.cashregister.utils.SystemUtils;
import com.ukao.cashregister.utils.T;
import com.ukao.cashregister.view.StockinView;
import com.ukao.cashregister.widget.ClearEditText;
import com.ukao.cashregister.widget.DividerDecoration;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

import static com.ukao.cashregister.consts.GlobalConsts.PAGE_REQUEST_CODE;

/**
 * Created by ukaodev on 2017/5/19.
 * 入库
 */

public class StorageFragment extends MvpFragment<StockinPesenter> implements StockinView {

    @BindView(R.id.stockin_list_footer_amount_more_btn)
    Button mListFooterAmountMoreBtn;
    @BindView(R.id.stockin_list_footer_edit_amount)
    Button mListFooterEditAmountBtn;

    @BindView(R.id.fragment_stockin_recycler)
    RecyclerView recycler;
    Unbinder unbinder;


    @BindView(R.id.enter_potpocket_btn)
    Button enterPotpocketBtn;
    @BindView(R.id.fragment_stockin_search_btn)
    Button fragmentStockinSearchBtn;
    @BindView(R.id.fragment_stockin_all_marking_btn)
    Button fragmentStockinAllMarkingBtn;
    @BindView(R.id.fragment_stockin_complete_btn)
    Button fragmentStockinCompleteBtn;
    @BindView(R.id.orderNo)
    TextView orderNo;
    @BindView(R.id.transNo)
    TextView transNo;
    @BindView(R.id.createTime)
    TextView createTime;
    @BindView(R.id.priority)
    TextView priority;
    @BindView(R.id.pat_state)
    TextView patState;
    @BindView(R.id.statusText)
    TextView statusText;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.phone)
    TextView phone;
    @BindView(R.id.cardNo)
    TextView cardNo;
    @BindView(R.id.cardName)
    TextView cardName;
    @BindView(R.id.balance)
    TextView balance;
    @BindView(R.id.no_data)
    TextView noData;
    @BindView(R.id.stockin_list_footer_add_btn)
    Button stockinListFooterAddBtn;
    @BindView(R.id.stockin_orders_list_footer_clothing_num)
    TextView stockinOrdersListFooterClothingNum;
    @BindView(R.id.annexTotal)
    TextView annexTotal;
    @BindView(R.id.paymentPrice)
    TextView paymentPrice;
    @BindView(R.id.stockin_orders_list_footer_tips)
    TextView stockinOrdersListFooterTips;
    @BindView(R.id.chage_image)
    ImageView chageImage;

    @BindView(R.id.fragment_stockin_search_edit)
    ClearEditText mSearchEdit;
    @BindView(R.id.print_receipt_btn)
    Button printReceiptBtn;
    @BindView(R.id.price_layout)
    LinearLayout priceLayout;
    @BindView(R.id.stockin_list_footer_submit_btn)
    Button mListFooterSubmitBtn;
    @BindView(R.id.clothing_count)
    TextView clothingCount;
    @BindView(R.id.transNo_btn)
    Button transNoBtn;
    @BindView(R.id.factory_transNo)
    TextView factoryTransNo;
    @BindView(R.id.tv_bloc_name1)
    TextView tvBlocName;  //集团名字
    @BindView(R.id.washing_btn)
    Button washingBtn;  //洗涤btn

    private String strOrderNo = "";
    public static final int ADD_CLTHING = 0X10;
    private List<StockinBean.ProListBean> modeldata = new ArrayList<>();
    private StockinAdapter mAdapter;
    private StockinBean.OrderInfoBean orderInfo;
    private List<StockinBean.ProListBean> proList;
    private View[] mView;
    private MercCityBean mlogisticsData;
    public String modifyPrice = "";
    public StockinBean.ProListBean item;/*刪除*/
    private StockinBean mStockinBean;
    private boolean ishowMarkDialog;
    private int hiteType;/*点击类型*/
    public final int COPE_HITE_TYPE = 1;
    public final int ADD_HITE_TYPE = 2;
    public final int CHAGE_HITE_TYPE = 3;
    public StockinBean.ProListBean ProListBean;
    private boolean isPayFinish = false;/*支付完成的状态*/
    private String payFinishMsg;
    private  String orderId;
    public static StorageFragment newInstance(String orderNum) {
        StorageFragment fragment = new StorageFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, orderNum);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            strOrderNo = getArguments().getString(ARG_PARAM1, "");

        }
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_stockin, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;

    }
    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
        initView();
        initListener();
        mvpPresenter.stockInMercCity(_mActivity);

    }

    @Override
    protected void initListener() {
        super.initListener();
        mSearchEdit.setOnEditorActionListener(mOnEditorActionListener);
        mAdapter.setOnItemChildClickListener(mOnItemChildClickListener);
        mAdapter.setOnItemClickListener(mOnItemClickListener);
    }

    private TextView.OnEditorActionListener mOnEditorActionListener = new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

            if (!CheckUtils.isNull(event) && event.getKeyCode() == KeyEvent.KEYCODE_ENTER || actionId == EditorInfo.IME_ACTION_DONE) {
                searchOrder();
                mSearchEdit.setText("");
            }

            return false;
        }
    };

    private OnItemClickListener mOnItemClickListener = new MyOnItemClickListener() {


        @Override
        public void onItemClick(ViewGroup viewGroup, View view, Object o, int i) {
            super.onItemClick(viewGroup, view, o, i);
            if (isPayFinish) {
                T.show(payFinishMsg);
                return;
            }
            ProListBean = (StockinBean.ProListBean) o;
            if (!ProListBean.isClothing()){
                T.show("附件不能修改");
                 return;
            }
            if (ishowMarkDialog && !mStockinBean.isEnableFinishStockIn()) {
                hiteType = CHAGE_HITE_TYPE;
                showMarkingHiteDialog();
            } else {
                Intent mIntent = startAddClothingActivity(ProListBean.getNo());
                mIntent.putExtra(ARG_PARAM4, ProListBean);
                startActivityForResult(mIntent, ADD_CLTHING);
            }


        }
    };

    protected OnItemChildClickListener mOnItemChildClickListener = new OnItemChildClickListener() {


        @Override
        public void onChildItemClick(int id, int pos) {
            item = mAdapter.getItem(pos);
            if (item==null)return;
            switch (id) {
                case R.id.stockin_list_item_delete_bt:/*删除*/

                    if (isPayFinish) {
                        T.show(payFinishMsg);
                        return;
                    }
                    int cloCnt = 0;
                    List<StockinBean.ProListBean> mData = mAdapter.getDatas();
                    for (StockinBean.ProListBean proListBean : mData) {
                        if (proListBean.isClothing()) {
                            cloCnt = cloCnt + 1;
                        }
                    }
                    if (cloCnt ==1&&item.isClothing()) {
                        T.show(getString(R.string.eep_least_one_garment));
                        return;
                    }
                    InquiryDialogFragment mInquiryDialog = InquiryDialogFragment.newInstance("");
                    mInquiryDialog.setOnSureClickListener(mOnDialogSureClick);
                    mInquiryDialog.show(getChildFragmentManager(), InquiryDialogFragment.class.getName());
                    break;
                case R.id.stockin_list_item_copy_bt:/*复制*/
                    if (isPayFinish) {
                        T.show(payFinishMsg);
                        return;
                    }
                    if (ishowMarkDialog && !mStockinBean.isEnableFinishStockIn()) {
                        hiteType = COPE_HITE_TYPE;
                        showMarkingHiteDialog();
                    } else {
                        mvpPresenter.copystockIn(_mActivity, orderInfo.getId(), item, proList.size());
                    }


                    break;

                case R.id.stockin_list_item_marking_bt:/*打标*/

                    if (CheckUsbDeviceUtils.isWashprinter()) {/*水洗*/
                        mvpPresenter.printWash(_mActivity, item.getId() );
                    }

                    break;
                case  R.id.bing_code_btn :  /*绑标*/
                    BindSignDialogFragment mBingSignDialog = BindSignDialogFragment.newInstance("","");
                    mBingSignDialog.setOnSureClickListener(message -> {
                        mvpPresenter.bindCode(item,(String)message);
                    });
                    mBingSignDialog.show(getChildFragmentManager(), BindSignDialogFragment.class.getName());
                      break;
                case R.id.stockin_list_item_photo_bt: /*照片*/
                    mvpPresenter.productImagelist(item.getId());
                    break;


            }
        }


    };

    private OnDialogSureClickListener mOnDialogSureClick = new OnDialogSureClickListener() {
        @Override
        public void onSureItemClick(Object message) {
            mvpPresenter.deleteStockIn(_mActivity, item.getId() + "", item);
        }
    };


    @OnClick({R.id.price_layout})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.price_layout:
                if (CheckUtils.isNull(orderInfo)) return;
                if (mListFooterAmountMoreBtn.getBackground().getCurrent().getConstantState().equals(getResources().getDrawable(R.drawable.list_footer_down).getConstantState())) {
                    mListFooterAmountMoreBtn.setBackgroundDrawable(getActivity().getResources().getDrawable(R.drawable.list_footer_up));
                    String tipaymentPricetle = CheckUtils.isEmptyNumber(orderInfo.getOrderPrice()) + "";
                    String sendCarriage = CheckUtils.isEmptyNumber(orderInfo.getSendCarriage()) + "";
                    String takeCarriage = CheckUtils.isEmptyNumber(orderInfo.getTakeCarriage()) + "";
                    DialogTool.getSingleton().showDialog(_mActivity, tipaymentPricetle, sendCarriage, takeCarriage, modifyPrice, mOnCancelListener);
                } else {
                    mListFooterAmountMoreBtn.setBackgroundDrawable(getActivity().getResources().getDrawable(R.drawable.list_footer_down));
                }
                break;
        }
    }


    private DialogInterface.OnCancelListener mOnCancelListener = new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            mListFooterAmountMoreBtn.setBackgroundDrawable(getActivity().getResources().getDrawable(R.drawable.list_footer_down));
        }
    };


    @Override
    protected StockinPesenter createPresenter() {
        return new StockinPesenter(this);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


    @Override
    protected void initView() {
        payFinishMsg = getResource().getString(R.string.finish_pay_no_play);
        ishowMarkDialog = true;
        if (!CheckUtils.isEmpty(strOrderNo)) {
            //mSearchEdit.setText(strOrderNo);
            mvpPresenter.searchStorage(_mActivity, strOrderNo);
        }
        mSearchEdit.requestFocus();
        recycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        recycler.addItemDecoration(new DividerDecoration(getActivity(), DividerDecoration.VERTICAL_LIST));
        modeldata.clear();
        mAdapter = new StockinAdapter(_mActivity, modeldata);
        recycler.setAdapter(mAdapter);

        mView = new View[]{stockinListFooterAddBtn, fragmentStockinCompleteBtn,};
        for (int i = 0; i < mView.length; i++) {
            mView[i].setEnabled(false);
            mView[i].setAlpha(0.5f);
        }

        mListFooterEditAmountBtn.setVisibility(View.GONE);
        mListFooterSubmitBtn.setVisibility(View.GONE);

    }


    @OnClick({R.id.print_receipt_btn, R.id.stockin_list_footer_add_btn, R.id.stockin_list_footer_submit_btn, R.id.fragment_stockin_search_btn,
            R.id.stockin_list_footer_edit_amount, R.id.fragment_stockin_complete_btn, R.id.fragment_stockin_all_marking_btn, R.id.transNo_btn
    ,R.id.enter_potpocket_btn,R.id.washing_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case  R.id.enter_potpocket_btn:
                if (CheckUtils.isNull(orderInfo))return;
                IntoBagDialogFragment mIntoBagDialog = IntoBagDialogFragment.newInstance(orderInfo.getId(),orderInfo.getOrderNo(),true);
                mIntoBagDialog.show(getChildFragmentManager(),IntoBagDialogFragment.class.getName());
                break;

            case R.id.transNo_btn:  /*添加运单号*/
                TansNoDialogFragment.createBuilder(getChildFragmentManager())
                        .title(getString(R.string.waybill_number))
                        .tansNo(orderInfo.getFactoryTransNo())
                        .mOnDialogSureClickListener(mOnDialogTansNoClickListener)
                        .show();

                break;

            case R.id.print_receipt_btn:/*打印小票*/
                if (CheckUtils.isNull(orderInfo)) return;
                if (CheckUtils.isMIUIDevices()){
                    mvpPresenter.printReceipt(_mActivity, orderInfo.getId());
                }else if (CheckUsbDeviceUtils.isReceipt()) {/*小票*/
                    mvpPresenter.printReceipt(_mActivity, orderInfo.getId());
                }
                break;

            case R.id.fragment_stockin_all_marking_btn:  /*全打标*/
                if (CheckUtils.isNull(orderInfo)) return;
                mvpPresenter.allprintWash(_mActivity, orderInfo.getId());
                break;
            case R.id.stockin_list_footer_add_btn:  //添加衣物
                if (CheckUtils.isNull(orderInfo)) return;
                if (ishowMarkDialog && !mStockinBean.isEnableFinishStockIn() && proList.size() != 0) {
                    hiteType = ADD_HITE_TYPE;
                    showMarkingHiteDialog();
                } else {
                    startActivityForResult(startAddClothingActivity(proList.size()), ADD_CLTHING);
                }

                break;
            case R.id.stockin_list_footer_submit_btn: /*收款*/
                if (!CheckUtils.isNull(orderInfo))
                    startForResult(GatheringFragment.newInstance(orderInfo.getId(), "返回入库"), PAGE_REQUEST_CODE);
                break;
            case R.id.fragment_stockin_search_btn:  //搜索按钮
                searchOrder();
                break;
            case R.id.stockin_list_footer_edit_amount:
                String  unitPice="订单金额" + ":￥" + getText(paymentPrice);
                SelectNumDialogFragment.createBuilder(getFragmentManager()).setmDialogTitle("修改总金额").
                        setUnitTitle("元").setUnitPice(unitPice).setModificationVisibility(true).
                        setListener(mOnDialogSureClickListener).show();
                break;
            case R.id.fragment_stockin_complete_btn:  //完成入库
                if (!CheckUtils.isEmpty(mAdapter.getDatas()))
                    mvpPresenter.finishStorage(_mActivity, orderInfo.getId());
                break;
            case R.id.washing_btn:  //洗涤按钮
                    mvpPresenter.proceedWashing(orderId);
                break;
        }
    }

    /**
     * 搜索订单
     */
    private void searchOrder() {
        strOrderNo = getText(mSearchEdit);
        if (!strOrderNo.isEmpty()) {
            hideSoftInput();
            mvpPresenter.searchStorage(_mActivity, strOrderNo);
        }
    }


    /**
     * 运单号
     */
    private OnDialogSureClickListener mOnDialogTansNoClickListener = new OnDialogSureClickListener() {


        @Override
        public void onSureItemClick(Object message) {
            mvpPresenter.updateFactoryTransNo(orderInfo.getId(), (String) message);

        }
    };

    private OnDialogSureClickListener mOnDialogSureClickListener = new OnDialogSureClickListener() {


        @Override
        public void onSureItemClick(Object message) {
            String modifyPrice = (String) message;
            String intModifyPrice = DecimalUtil.multiply(modifyPrice);
            mvpPresenter.modifyPrice(_mActivity, orderInfo.getId(), intModifyPrice, modifyPrice);
        }
    };

    private Intent startAddClothingActivity(int sortNo) {
        Intent mIntent = new Intent(activity, AddClothingActivity.class);
        mIntent.putExtra(ARG_PARAM1, orderInfo.getId());
        mIntent.putExtra(ARG_PARAM2, orderInfo.getPricingMode() + "");
        mIntent.putExtra(ARG_PARAM3, sortNo);
        return mIntent;

    }

    @Override
    public void getDataSuccess(StockinBean model) {
        SystemUtils.hideInputmethod(mSearchEdit);
        isPayFinish = false;
        mStockinBean = model;
        orderInfo = model.getOrderInfo();
        orderId=orderInfo.getId();  //订单id
        mAdapter.getDatas().clear();
        strOrderNo = orderInfo.getOrderNo();
        orderNo.setText(CheckUtils.isEmptyString(orderInfo.getOrderNo()));
        transNo.setText(CheckUtils.isEmptyString(orderInfo.getTransNo()));
        createTime.setText(MyDateUtils.formatDataTime(orderInfo.getCreateTime()));
        priority.setText(orderInfo.getPriority() == 1 ? "加急" : "普通");      /*订单优先级 0.普通 1.加急*/
        if(!TextUtils.isEmpty(orderInfo.getUserInfo().getUnionName())){
            tvBlocName.setCompoundDrawablesWithIntrinsicBounds(R.drawable.bloc,0,0,0);
            tvBlocName.setCompoundDrawablePadding(DensityUtils.dip2px(getActivity(),5));
            tvBlocName.setText(orderInfo.getUserInfo().getUnionName());
        }
        statusText.setText(orderInfo.getStatusText());
        Integer createCnt = orderInfo.getCreateCnt();
        if (!CheckUtils.isNull(createCnt)) {
            clothingCount.setText(createCnt + "");  /*衣物件数*/
        } else {
            clothingCount.setText("");
        }

        StockinBean.OrderInfoBean.UserInfoBean userInfo = orderInfo.getUserInfo();
        name.setText(CheckUtils.isEmptyString(userInfo.getName()));
        phone.setText(CheckUtils.isEmptyString(userInfo.getPhone()));
        cardNo.setText(CheckUtils.isEmptyString(userInfo.getRfidNo()));
        String discount = CheckUtils.isDiscount(userInfo.getCardDiscount(),userInfo.getDiscountType());
//        if (discount.equals("无折扣")) {
//            discount = "";
//        }
        factoryTransNo.setText(CheckUtils.isEmptyString(orderInfo.getFactoryTransNo()));
        transNoBtn.setText(CheckUtils.isEmpty(orderInfo.getFactoryTransNo())?getString(R.string.waybill_number)
                :getString(R.string.modified_number)); /*工厂运单号*/
        transNoBtn.setVisibility(model.isEnableUpdateFactoryTransNo() ? View.VISIBLE : View.GONE);
        cardName.setText(CheckUtils.isEmptyString(userInfo.getCardName()) + "/"+discount);
        balance.setText(CheckUtils.isEmptyNumber(userInfo.getBalance()) + "");
        mAdapter.setProTotal(model.getProTotal());
        proList = model.getProList();
        stockinOrdersListFooterClothingNum.setText(model.getProTotal()+ "");
        chageImage.setVisibility(orderInfo.getIsModifyPrice() ? View.VISIBLE : View.GONE);
        modifyPrice = orderInfo.getIsModifyPrice() ? CheckUtils.isEmptyNumber(orderInfo.getPaymentPrice()) : "";
        paymentPrice.setText(CheckUtils.isEmptyNumber(orderInfo.getPaymentPrice()));
        annexTotal.setText(CheckUtils.isEmptyString(model.getAnnexTotal()));
        enterPotpocketBtn.setVisibility(model.isEnableBatchIn()?View.VISIBLE:View.GONE);
        if (CheckUtils.isEmpty(proList)) {
            mAdapter.getDatas().clear();
            mAdapter.notifyDataSetChanged();
            noData.setVisibility(View.VISIBLE);
            recycler.setVisibility(View.GONE);

        } else {
            setEnabledBtn(fragmentStockinAllMarkingBtn, model.isEnableFinishStockIn() ? false : true);
            if (model.isEnableFinishStockIn()) {/*是否完成入库*/
                mAdapter.setShowMarkBtn(false);
            } else {
                mAdapter.setShowMarkBtn(true);
            }
            mAdapter.setDatas(proList);
            noData.setVisibility(View.GONE);
            recycler.setVisibility(View.VISIBLE);

        }
        stockinListFooterAddBtn.setEnabled(true);
        stockinListFooterAddBtn.setAlpha(1);

        printReceiptBtn.setVisibility(model.isEnablePrint() ? View.VISIBLE : View.GONE);
        setEnabledBtn(fragmentStockinCompleteBtn, model.isEnableFinishStockIn() ? true : false);
        setEnabledBtn(mListFooterEditAmountBtn, model.isEnableModifyPrice() && !model.isPaid() ? true : false);
        setEnabledBtn(mListFooterSubmitBtn, model.isEnablePay() && !model.isPaid() ? true : false);
        setPayStateText(model.isPaid());
    }

    private void setPayStateText(boolean isPaid) {
        if (isPaid) {/*已付款*/
            patState.setText("已付款");
            patState.setTextColor(resources.getColor(R.color.green));

        } else {
            patState.setText("未付款");
            patState.setTextColor(resources.getColor(R.color.red));
        }
    }

    public void setEnabledBtn(Button mButton, boolean enabled) {
        if (enabled) {
            if (mButton == fragmentStockinCompleteBtn) {
                mButton.setAlpha(1);
                mButton.setEnabled(true);
            }

            mButton.setVisibility(View.VISIBLE);

        } else {

            mButton.setVisibility(View.GONE);


        }

    }


    @Override
    public void deleteStockInSuccess(String message, StockinBean.ProListBean pos) {
        List<StockinBean.ProListBean> mData = mAdapter.getDatas();
        mData.remove(pos);
        mAdapter.notifyDataSetChanged();
        mvpPresenter.searchStorage(_mActivity, strOrderNo);
    }
    @Override
    public void logisticsSuccess(MercCityBean model) {
        mlogisticsData = model.getData();
        if (mlogisticsData.getIsCarriage() == 1) {
            stockinOrdersListFooterTips.setText("订单总额未满" + CheckUtils.isEmptyNumber(mlogisticsData.getFreeCarriageAmt())
                    + "加收服务费：" + "取件费" + CheckUtils.isEmptyNumber(mlogisticsData.getTakeCarriage()) + "元," + "送件费" + CheckUtils.isEmptyNumber(mlogisticsData.getSendCarriage())
                    + "元")
            ;
        }
    }

    @Override
    public void copySuccess(String message) {
        T.show(message);
        mvpPresenter.searchStorage(_mActivity, strOrderNo);
    }


    @Override
    public void loadFail(String message) {
        T.show(message);
    }


    /**
     * 修改金额成功
     */
    @Override
    public void modifySuccess(String mModifySuccess) {
        modifyPrice = mModifySuccess;
        paymentPrice.setText(mModifySuccess);
        orderInfo.setIsModifyPrice(1); /*是否被修改过*/
        chageImage.setVisibility(orderInfo.getIsModifyPrice() ? View.VISIBLE : View.GONE);
    }

    /**
     * 完成入库
     *
     * @param msg
     */
    @Override
    public void finishStorageSucceed(String msg) {
        statusText.setText("已入库");
        enterPotpocketBtn.setVisibility(View.VISIBLE);
        mStockinBean.setEnableFinishStockIn(false);
        printReceiptBtn.setVisibility(View.VISIBLE);
        washingBtn.setVisibility(View.VISIBLE);  //显示洗涤按钮
        setEnabledBtn(fragmentStockinCompleteBtn, false);
        setEnabledBtn(fragmentStockinAllMarkingBtn, true);
        mAdapter.setShowMarkBtn(true);
        mAdapter.notifyDataSetChanged();
        if (!mStockinBean.isPaid()) {
            setEnabledBtn(mListFooterEditAmountBtn, true);
            setEnabledBtn(mListFooterSubmitBtn, true);
        }
        T.show(msg);
    }

    @Override
    public void loadReceipt(ReceiptBean mReceiptBean) {
        if (CheckUtils.isMIUIDevices()) {  //商米打印
            PrintMiuiHelper.receiptReceipt(MainActivity.getPrintService(),mReceiptBean);
        }else{    //不是商米打印
            GpDevice mDevice = new GpDevice();
            PrinterReceipt.getInstance().printGp80(mReceiptBean,mDevice);
        }
    }


    /**
     * 打标
     */
    @Override
    public void marKprintSucceed(MarkprintBean mMarkprintBean) {
        PrinterHelper.getInstance().printWashing(mMarkprintBean);

    }

    /**
     * 全部打标
     */
    @Override
    public void allmarKprintSucceed(AllMarkprintBean mMarkprintBean) {

        if (CheckUsbDeviceUtils.isWashprinter()) {/*水洗*/
            PrinterHelper.getInstance().printAllWashings(mMarkprintBean);
        }


    }

    @Override
    public void loadPayStatus(PayInfoBean mPayInfoBean) {
        if (mPayInfoBean.getPayStatus()) {

        } else {
            //  T.show("您已付过款");

        }
    }

    @Override
    public void photoListSucceed(ArrayList<ProductRelImgBean> mProductRelImgData, String orderProId) {
        //如果是商米设备
        Intent intent;
        if (CheckUtils.isMIUIDevices()){
            intent = new Intent(_mActivity, CameraSunMiActivity.class);
        }else {
            intent = new Intent(_mActivity, CameraActivity.class);
        }
        intent.putExtra(ARG_PARAM1, orderProId);
        intent.putExtra(ARG_PARAM2, mProductRelImgData);
        startActivityForResult(intent, AppConstant.REQUEST_CODE.CAMERA);
    }


    /**
     * 工厂运单号
     *
     * @param updateTransNo
     */
    @Override
    public void updateFactorySucceed(String updateTransNo) {
        factoryTransNo.setText(updateTransNo);
        orderInfo.setFactoryTransNo(updateTransNo);
        transNoBtn.setText(R.string.modified_number);

    }

    /**
     * 绑标成功
     */
    @Override
    public void bindCodeSucceed(StockinBean.ProListBean item) {
        int index = mAdapter.getDatas().indexOf(item);
        if (index!=-1){
            mAdapter.notifyItemChanged(index);
        }
    }

    @Override
    public void washingSucceed() {
        washingBtn.setText("洗涤中");
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case ADD_CLTHING:
                    if (CheckUtils.isNull(orderInfo)) return;
                    mvpPresenter.searchStorage(_mActivity, orderInfo.getOrderNo());
                    break;
                case AppConstant.REQUEST_CODE.CAMERA:/*获取照片数量*/
                    String orderProId = data.getStringExtra(ARG_PARAM1);
                    int phntoCount = data.getIntExtra(ARG_PARAM2, 0);
                    for (StockinBean.ProListBean proListBean : mAdapter.getDatas()) {
                        String orderProIds = String.valueOf(proListBean.getId());
                        if (orderProIds.equals(orderProId)) {
                            proListBean.setPicCnt(phntoCount);
                        }
                    }
                    mAdapter.notifyDataSetChanged();

                    break;

            }
        }
    }

    @Override
    protected void onFragmentResult(int requestCode, int resultCode, Bundle data) {
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case PAGE_REQUEST_CODE:


//                    clothingCount.setText("");
//                    fragmentStockinAllMarkingBtn.setVisibility(View.GONE);
//                    mSearchEdit.setText("");
//                    orderNo.setText("");
//                    transNo.setText("");
//                    createTime.setText("");
//                    priority.setText("");    /*订单优先级 0.普通 1.加急*/
//                    patState.setText("");
//                    statusText.setText("");
//                    name.setText("");
//                    phone.setText("");
//                    cardNo.setText("");
//                    cardName.setText("");
//                    vipCardBalance.setText("");
//                    stockinOrdersListFooterClothingNum.setText("0");
//                    chageImage.setVisibility(View.GONE);
//                    paymentPrice.setText("0");
//                    annexTotal.setText("0");
//                    mAdapter.getDatas().clear();
//                    mAdapter.notifyDataSetChanged();
//                    orderInfo = null;
//

                    isPayFinish = true;
                    setPayStateText(true);
                    for (int i = 0; i < mView.length; i++) {
                        mView[i].setVisibility(View.VISIBLE);
                        mView[i].setEnabled(false);
                        mView[i].setAlpha(0.5f);
                    }
                    mListFooterEditAmountBtn.setVisibility(View.GONE);
                    mListFooterSubmitBtn.setVisibility(View.GONE);
                    break;
            }
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (!CheckUtils.isNull(PrinterHelper.getInstance())) {
            PrinterHelper.getInstance().onDestroy();
        }
    }

    /**
     * 打标提示
     */
    public void showMarkingHiteDialog() {
        if (fragmentStockinCompleteBtn.getVisibility() == View.GONE) {
            InquiryDialogFragment mInquiryDialog = InquiryDialogFragment.newInstance("本订单已操作完成入库，请修改后重新打印水洗标");
            mInquiryDialog.setOnSureClickListener(mwMarkingHiteClick);
            mInquiryDialog.show(getChildFragmentManager(), InquiryDialogFragment.class.getName());
            ishowMarkDialog = false;

        }


    }

    private OnDialogSureClickListener mwMarkingHiteClick = new OnDialogSureClickListener() {
        @Override
        public void onSureItemClick(Object message) {
            switch (hiteType) {
                case COPE_HITE_TYPE:
                    mvpPresenter.copystockIn(_mActivity, orderInfo.getId(), item, proList.size());
                    break;
                case ADD_HITE_TYPE:
                    startActivityForResult(startAddClothingActivity(proList.size()), ADD_CLTHING);
                    break;
                case CHAGE_HITE_TYPE:
                    Intent mIntent = startAddClothingActivity(ProListBean.getNo());
                    mIntent.putExtra(ARG_PARAM4, ProListBean);
                    startActivityForResult(mIntent, ADD_CLTHING);
                    break;

            }
        }
    };
}